#!/bin/bash

# Script that prompts user questions for static IP address set up

# Uncomment for full system update
# su -c 'yum update'

echo -n "Enter desired IP Address for this machine: "
read ipaddr
#echo -n "Enter netmask: "
#read netmask
#echo -n "Enter Broadcast Address: "
#read broadcast

hostname=${ipaddr//.//_}
gateway="192.168.1.1"
netmask="24"
uuid=$(cat "/proc/sys/kernel/random/uuid")

hostnamectl set-hostname $hostname

cat >/etc/sysconfig/network <<EOL
NETWORKING=yes
HOSTNAME=$hostname
GATEWAY=$gateway
EOL

cat >/etc/hosts <<EOL
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 $hostname
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
EOL



cat >/etc/sysconfig/network-scripts/ifcfg-ens192 <<EOL
TYPE="Ethernet"
BOOTPROTO="static"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
NAME="ens192"
UUID="${uuid}"
DEVICE="ens192"
ONBOOT="yes"
IPADDR="${ipaddr}"
PREFIX="${netmask}"
GATEWAY="${gateway}"
IPV6_PEERDNS="yes"
IPV6_PEERROUTES="yes"
IPV6_PRIVACY="no"
DNS1=8.8.8.8
DNS2=8.8.4.4
EOL

#service network restart
reboot